package cn.tedu.qxhouserent.house.controller;

import cn.tedu.qxhouserent.commons.pojo.vo.PageData;
import cn.tedu.qxhouserent.commons.security.LoginPrincipal;
import cn.tedu.qxhouserent.commons.web.JsonResult;
import cn.tedu.qxhouserent.house.pojo.param.UserHouseAppointParam;
import cn.tedu.qxhouserent.house.pojo.vo.UserHouseAppointVO;
import cn.tedu.qxhouserent.house.service.UserHouseAppointService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/UHA")
@Api(tags = "房屋预约功能")
@Slf4j
@Validated
public class UserHouseAppointController {
    @Autowired
    private UserHouseAppointService service;

    @PostMapping("/yuekan")
    @ApiOperation("预约看房")
    @ApiOperationSupport(order = 100)
    public JsonResult yuekan(@Validated UserHouseAppointParam u,@AuthenticationPrincipal LoginPrincipal l){
        System.out.println(LocalDateTime.now());
        log.debug("开始处理预约看房功能:{}",u);
        String s = service.yukan(u, l);
        return JsonResult.ok(s);
    }

    @GetMapping("/yuecha")
    @ApiOperation("查看预约")
    @ApiOperationSupport(order = 110)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query"),

    })
    public JsonResult yuecha(@AuthenticationPrincipal LoginPrincipal l,@RequestParam @Range(min = 1, message = "查询用户列表失败，请提供正确的页码值！") Integer page){
        log.debug("开始处理查询预约看房功能");
        if (page == null || page < 1) {
            page = 1;
        }
        PageData<UserHouseAppointVO> s = service.yuecha(l, page);
        return JsonResult.ok(s);
    }
}
